import Request from "./request";
// import { getAccessToken } from "@/utils/auth";
import { useLogin } from "@/store";
const timeOut = 60000;
const userId = "032601";
export const http = new Request({
  baseURL: import.meta.env.VITE_BASE_API_URL + "",
  timeout: timeOut,
  headers: {
    "Content-Type": "application/json",
    "ngrok-skip-browser-warning": true,
  },
  interceptors: {
    requestInterceptor: (config) => {
      const currentToken = useLogin().access_token;
      if (currentToken) {
        config.headers!.Authorization = `Bearer ${currentToken}`;
      }
      const clientId = useLogin().client_id;
      if (currentToken) {
        config.headers!.clientId = clientId;
      }
      const currentUserId = useLogin().user;
      if (currentUserId) {
        config.headers!.userId = currentUserId;
      }

      config.headers!.userId = userId;
      return config;
    },
  },
});

// export const https = new Request({
//   baseURL: 'http://121.40.98.52',
//   timeout: timeOut,
//   headers: { 'Content-Type': 'application/json', 'ngrok-skip-browser-warning': true},
//   interceptors: {
//     requestInterceptor: (config) => {
//       const currentToken = useLogin().access_token;
//       if(currentToken){
//         config.headers!.Authorization = `Bearer ${currentToken}`;
//       }
//       const clientId = useLogin().client_id;
//       if(currentToken){
//         config.headers!.clientId = clientId;
//       }
//       const currentUserId = useLogin().user;
//       if(currentUserId){
//         config.headers!.userId = currentUserId;
//       }

//       config.headers!.userId = userId;
//       return config;
//     },
//   },
// });

export const httppp = new Request({
  baseURL: "https://328d44s041.oicp.vip",
  timeout: timeOut,
  headers: {
    "Content-Type": "multipart/form-data",
    "ngrok-skip-browser-warning": true,
  },
  interceptors: {
    requestInterceptor: (config) => {
      const currentToken = useLogin().access_token;
      if (currentToken) {
        config.headers!.Authorization = `Bearer ${currentToken}`;
      }
      const clientId = useLogin().client_id;
      if (currentToken) {
        config.headers!.clientId = clientId;
      }
      const currentUserId = useLogin().user;
      if (currentUserId) {
        config.headers!.userId = currentUserId;
      }
      return config;
    },
  },
});
// export default http;
